package com.all.play.mymvpthree.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.all.play.mymvpthree.R;
import com.all.play.mymvpthree.bean.InfoBean;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/5/16.
 * Time: 2018/5/16  9:51
 */

public class MyAdapter extends BaseAdapter {
    private Context context;
    private List<InfoBean.DataBean> data;

    public MyAdapter(Context context, List<InfoBean.DataBean> data) {

        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data==null?0:data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView==null){
            vh=new ViewHolder();
            convertView=View.inflate(parent.getContext(), R.layout.item,null);
            vh.item1=convertView.findViewById(R.id.tv_item1);
            vh.item2=convertView.findViewById(R.id.tv_item2);

            convertView.setTag(vh);
        }else{
            vh= (ViewHolder) convertView.getTag();
        }

        vh.item1.setText(data.get(position).getFtime());
        vh.item2.setText(data.get(position).getContext());


        return convertView;
    }

    static class ViewHolder{
        TextView item1;
        TextView item2;
    }
}
